home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
L' Effet Pommier 3
/
L'Effet Pommier - Volume 03.iso
/
HyperCard-SuperCard
/
XCMD Docs
/
CompileIt! Source Code
/
RectToRGBW(rect,blackColor)
< prev
next >
Wrap
Text File
|
1995-08-20
|
3KB
|
98 lines
global rgb:R[6],red1:L,green1:L,blue1:L
-- we must do this or CompileIt! will used signed numbers (example: Compile would call 65535 negetive one)
global blackC:C
function RectToRGBW rect,blackColor
put blackColor into BlackC
put item 1 of rect*1 into r1
put item 2 of rect*1 into r2
put item 3 of rect*1 into r3
put item 4 of rect*1 into r4
put ((r3-r1)*(r4-r2))+1 into size1 -- this will calculate the size of the handle needed.
put NewHandleClear(size1) into hand
put 1 into byteNum -- we could calculate this in the repeat using arithmatic, but doing so would be SLOW. Counting up is a LOT FASTER!
repeat with v=r2 to r4
repeat with h=r1 to r3
GetCPixel h,v,rgb
put rgb.integerType[1] into red1.integerType[2] -- this lets us sneek by CompileIt!'s signed numbers.
put rgb.integerType[2] into green1.integerType[2]
put rgb.integerType[3] into blue1.integerType[2]
-- **************TAKE CARE OF FAST STUFF FIRST*********************
if red1>green1 and red1>blue1 then
put "r" into char byteNum of handle hand
add one to byteNum
next repeat
end if
if green1>red1 and green1>blue1 then
put "g" into char byteNum of handle hand
add one to byteNum
next repeat
end if
if blue1>green1 and blue1>red1 then
put "b" into char byteNum of handle hand
add one to byteNum
next repeat
end if
if red1=0 and green1=0 and blue1=0 then
put blackC into char byteNum of handle hand
add one to byteNum
next repeat
end if
if red1=green1 and red1=blue1 then
put "w" into char byteNum of handle hand
add one to byteNum
next repeat
end if
if red1=green1 and red1>blue1 then
put "y" into char byteNum of handle hand
add one to byteNum
next repeat
end if
if red1=blue1 and red1>green1 then
put char (the random of 2) of "rb" into char byteNum of handle hand
add one to byteNum
next repeat
end if
if green1=blue1 and green1>red1 then
put char (the random of 2) of "gb" into char byteNum of handle hand
add one to byteNum
next repeat
end if
-- **************END OF FAST STUFF. NOW FOR SLOWER STUFF****************
-- This checks which it is closer too, if the others do not catch it...
-- This may never be written, because it may not be nessisary!?!?!?!?!? Is It????
-- If it ever executes, it will beep four times. It will then return 3 numbers. I would like to see these numbers
-- First let's define a few colors
-- White=65535,65535,65535
-- Red=65535,0,0
-- Green=0,65535,0
-- Blue=0,0,65535
-- Now, lets find the closest match:
put 65535-red1 into redDiff
put 65535-green1 into greenDif
put 65535-blue1 into blueDiff
-- (by now, source size>machine code size, and Compiled HyperTalk>library!)
sysBeep 10
sysBeep 10
sysBeep 10
sysBeep 10
disposeHandle hand
return red1 && green1 && blue1
end repeat
end repeat
return HyperCardText(Hand)
end RectToRGBW